package com.masu.knows.portal.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

/**
 * @author 沈传尚
 * @date 2022/3/29
 */
@Slf4j
@RestController
public class UploadController {

    @PostMapping("/upload/file")
    public String uploadFile(MultipartFile imageFile) throws IOException {
        // 确定上传的文件夹
        File folder=new File("D:/upload0329");
        folder.mkdirs();
        // 获得用户上传的文件名
        String filename = imageFile.getOriginalFilename();
        log.debug("获得的文件名为:{}",filename);
        // 创建文件代表要保存的文件路径和名称 F:/upload/a.jpg
        File file=new File(folder,filename);
        log.debug("复制到路径:{}", file.getAbsolutePath());
        // 执行上传
        imageFile.transferTo(file);
        return "upload success!";

    }
}
